package com.anrong.wulansdk.sdk.receiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.sax.StartElementListener;

import com.anrong.wulansdk.sdk.service.UploadService;
import com.anrong.wulansdk.sdk.utils.MyLogcat;

/**
 * 接收网络状态改变的广播
 * @author cxy
 *
 */
public class ConnectivityReceiver extends BroadcastReceiver { 

	@Override  
	public void onReceive(Context context, Intent intent) {  
		// TODO Auto-generated method stub  
		ConnectivityManager connectivityManager = (ConnectivityManager)  context.getSystemService(Context.CONNECTIVITY_SERVICE);  

//		NetworkInfo networkInfo = intent.getParcelableExtra(ConnectivityManager.EXTRA_NETWORK_INFO);  


		NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();  

		if (activeNetworkInfo != null) {  
			MyLogcat.log("Active Network Type  = " + activeNetworkInfo.getTypeName());  
			MyLogcat.log("Active Network Type  = " + activeNetworkInfo.getType());  
			MyLogcat.log("Active Network State = " + activeNetworkInfo.getState());  
			if (activeNetworkInfo.isConnected() ) {  
				MyLogcat.log("网络已连接");
				
			}  
		} else {  
			MyLogcat.log("网络不可用");
		}  

	}
}
